package svnkitDemo;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

public class FileView {

	public static List<File> allFile = new ArrayList<File>();

	public static void scan(File mFile) {
		if (mFile.isFile()) {
			allFile.add(mFile);
		} else if (mFile.isDirectory()) {
			String[] str = mFile.list();
			int size = str.length;
			for (int i = 0; i < size; i++) {
				String path = mFile.getPath() + "/" + str[i];
				scan(new File(path));
			}
		}
	}

	public String getPath(File mFile) {
		String fullPath = mFile.getPath();
		return fullPath;
	}

	public static List<File> getAllFile() {
		return allFile;
	}

	public static void setAllFile(List<File> allFile) {
		FileView.allFile = allFile;
	}

	private static void saveFile2Map(List<String> dirList, boolean isDeepScan) {
		String n;
		String fn;
		for (String dir : dirList) {
			FileView.scan(new File(dir));
			List<File> configPathList = FileView.getAllFile();
			for (File file : configPathList) {
				fn = file.getName();
				n = fn.substring(0, fn.indexOf("."));
				System.out.println(n + "=" + file.getPath());
			}
			if (configPathList != null) {
				configPathList.clear();
			}
		}
		if (dirList != null) {
			dirList.clear();
		}
	}

	public static void main(String[] args) {
		String WORK_HOME = "i:/workspace70/yndx_pginterface/";
		String scanPath = "classes/com/ailk/pg/util/sql";
		FileView.scan(new File(WORK_HOME + scanPath));
		List<File> list = FileView.getAllFile();
		int size = list.size();
		File file = null;
		String path = null;

		createUpdate(scanPath, list, size);
	}

	private static void createUpdate(String scanPath, List<File> list, int size) {
		File file;
		String path;
		// updateFile.sh
		System.out.println("mkdir $workDir/" + scanPath);
		for (int i = 0; i < size; i++) {
			file = list.get(i);
			path = StringUtils.replace(file.getPath(), "\\", "/");
			String all = "cp $sourceFileDir/" + file.getName()
					+ "    $workDir/";
			all += path.substring(path.indexOf(scanPath));
			System.out.println(all);
		}
	}

}